require("../util.js");
require("../component/components.js");
require("../component/basicSlide.js");
require("../../jsMt/util.js");
var userInfo=JSON.parse(sessionStorage.getItem("userInfo"));
if(!userInfo){
    location.href="/loginIndex"
}
var vm = new Vue({
    el:"#shopIndex",
    data:{
        type:1,
        shopId:"",   // 1.支付成功   2.拼团成功  3、拼团失败
        // userInfo:userInfo,
        loginUid:userInfo.loginUid,
        shopById:{},
        shopInfo:{},
        pageNumber:1,
        shopList:{},
        shopList1:[],
        shopList2:[],
        isMoreDiv:false
    },
    mounted:function(){
        this.searchObject = this.getQueryStringArgs();
        this.shopId=this.searchObject&&this.searchObject.shopId;
        this.getShopById();
        this.getShopList();
    },
    methods:{
        //后退
        getBack: function () {
            history.go(-1);
        },
        bgimg: function (url) {
            url = url ? url : "";
            return {
                "background-image": 'url("' + url + '"),url("")'
            }
        },
        /*获取查询字符对象*/
        getQueryStringArgs: function () {
            //取得查询字符串并去掉开头的问号
            var qs = (location.search.length > 0 ? location.search.substring(1) : ""),
                args = {},
                items = qs.length ? qs.split("&") : [],
                item = null,
                name = null,
                value = null,
                len = items.length;
            for (var i = 0; i < len; i++) {
                item = items[i].split("=");
                name = item[0];
                value = item[1];
                if (name.length) {
                    args[name] = value;
                }
            }
            return args;
        },
        //店铺页
        getShopById:function(){
            var that=this,data;
            data={
                loginUid:that.loginUid,
                shopId:that.shopId
            };
            this.ajax({url:"/purchase/getShopById",data:data,dataType:"json",method:"post"},function(b){
                if(b.json.code==0&&b.json.data){
                    that.shopById=b.json.data;
                }else{
                    vm.$refs.prompt.toast("获取店铺信息失败！")
                }
            });
        },
        // //店铺信息
        // getShopInfo:function(){
        //     var that=this;
        //     this.ajax({url:"/purchase/getShopInfo",data:{shopId:that.shopId},dataType:"json",method:"post"},function(b){
        //         if(b.json.code==0&&b.json.data){
        //             that.shopInfo=b.json.data;
        //         }else{
        //             vm.$refs.prompt.toast("获取店铺信息失败！")
        //         }
        //     });
        // },
        //店铺列表
        getShopList:function(type){
            var that=this,data,url;
            data={
                pageNumber:that.pageNumber,
                shopId:that.shopId
            };
            if(type){
                that.type=type;
            }
            if(that.type==1){
                url="/purchase/getShopRemProduct";
            }else if(that.type==2){
                url="/purchase/getShopProduct";
            }else if(that.type==3){
                url="/purchase/getShopProductByOrder";
            }else if(that.type==4){
                url="/purchase/getShopProductByCreate";
            }
            this.ajax({url:url,data:data,dataType:"json",method:"post"},function(b){
                if(b.json.code==0&&b.json.data){
                    that.shopList=b.json.data;
                    that.shopList1=that.shopList.list;
                    if(that.shopList.pageNumber>1){
                        if(that.shopList.list.length>0) {
                            that.shopList2 = that.shopList2.concat(b.json.data.list);
                        }
                    }else{
                        that.shopList2= that.shopList1;
                    }
                    vm.loadFlag=false;
                }else{
                    vm.$refs.prompt.toast("获取列表失败！")
                }
            });
        },
        //收藏（取消收藏）
        collectShopById:function(){
            var that=this;
            var data={
                loginUid:that.loginUid,
                shopId:that.shopId
                // state:that.praiseState
            };
            if(that.shopById.isCollect==0){
                data.state=1;    //1 收藏  0 取消
            }else{
                data.state=0;
            }
            console.log(data);
            this.ajax({url:"/purchase/collectShopById",data:data,dataType:"json",method:"post"},function(b){
                if(b.json.code==0){
                    // that.praiseCount=b.json.data;
                    if(that.shopById.isCollect==0){
                        that.shopById.isCollect=1;
                    }else{
                        that.shopById.isCollect=0;
                    }
                    that.getShopById();
                    // console.log(that.praiseCount)
                }else{
                    vm.$refs.prompt.toast("点赞失败！")
                }
            });
        },
        //显示隐藏
        getMoreDiv:function(){
            this.isMoreDiv=!this.isMoreDiv;
        },
        //跳转页面
        getNext:function(type,item){
            if(type==1){
                location.href="/purchase/shopDetails?shopId="+this.shopId;
            }else if(type==2){
                location.href="/purchase/shoppingCart"
            }else if(type==3){
                location.href="/purchase"
            }else if(type==4){
                location.href="/cityAd/citySearch?type=2"
            }else if(type==5){
                location.href="/purchase/goodsDetails?type=1&productId="+item.productId
            }
        }
    }
});
